package urban_elements

import (
	"fmt"
	"strconv"
)

// 类型
var elementType = map[int]map[string]interface{}{
	1: map[string]interface{}{
		"en_name": "Tourist",
		"cn_name": "景点",
		"sign":    "tourist",
		"children": map[int]map[string]string{
			1001: map[string]string{
				"en_name": "Amusement Park",
				"cn_name": "主题公园",
				"sort":    "1",
			},
			1002: map[string]string{
				"en_name": "volcano",
				"cn_name": "火山",
				"sort":    "2",
			},
			1003: map[string]string{
				"en_name": "Religion",
				"cn_name": "宗教",
				"sort":    "3",
			},
			1004: map[string]string{
				"en_name": "History",
				"cn_name": "历史",
				"sort":    "4",
			},
			1005: map[string]string{
				"en_name": "Beach",
				"cn_name": "沙滩",
				"sort":    "5",
			},
			1006: map[string]string{
				"en_name": "Park",
				"cn_name": "公园",
				"sort":    "6",
			},
			1007: map[string]string{
				"en_name": "Zoo",
				"cn_name": "动物园",
				"sort":    "7",
			},
			1008: map[string]string{
				"en_name": "Aquarium",
				"cn_name": "海洋馆",
				"sort":    "8",
			},
			1009: map[string]string{
				"en_name": "Museum",
				"cn_name": "博物馆",
				"sort":    "9",
			},
			1010: map[string]string{
				"en_name": "National customs",
				"cn_name": "民俗",
				"sort":    "10",
			},
			1011: map[string]string{
				"en_name": "Island",
				"cn_name": "岛屿",
				"sort":    "11",
			},
			1012: map[string]string{
				"en_name": "Themed Restaurant",
				"cn_name": "主题餐厅",
				"sort":    "12",
			},
			1013: map[string]string{
				"en_name": "Farm",
				"cn_name": "农场",
				"sort":    "13",
			},
			1014: map[string]string{
				"en_name": "View",
				"cn_name": "观景台",
				"sort":    "14",
			},
			1015: map[string]string{
				"en_name": "View",
				"cn_name": "名胜古迹",
				"sort":    "15",
			},
		},
	},
	2: map[string]interface{}{
		"en_name": "Food",
		"cn_name": "美食",
		"sign":    "food",
		"children": map[int]map[string]string{
			2001: map[string]string{
				"en_name": "Local Cuiseh",
				"cn_name": "本地菜",
				"sort":    "1",
			},
			2002: map[string]string{
				"en_name": "Local Cuiseh",
				"cn_name": "川菜",
				"sort":    "2",
			},
			2003: map[string]string{
				"en_name": "Local Cuiseh",
				"cn_name": "粤菜",
				"sort":    "3",
			},
			2004: map[string]string{
				"en_name": "Local Cuiseh",
				"cn_name": "面点",
				"sort":    "4",
			},
			2005: map[string]string{
				"en_name": "Local Cuiseh",
				"cn_name": "火锅",
				"sort":    "5",
			},
			2006: map[string]string{
				"en_name": "Local Cuiseh",
				"cn_name": "烧烤",
				"sort":    "6",
			},
			2007: map[string]string{
				"en_name": "Local Cuiseh",
				"cn_name": "烧烤",
				"sort":    "7",
			},
			2008: map[string]string{
				"en_name": "Local Cuiseh",
				"cn_name": "湘菜",
				"sort":    "8",
			},
			2009: map[string]string{
				"en_name": "Local Cuiseh",
				"cn_name": "家常",
				"sort":    "9",
			},
			2010: map[string]string{
				"en_name": "Local Cuiseh",
				"cn_name": "综合",
				"sort":    "10",
			},
		},
	},
	3: map[string]interface{}{
		"en_name": "Fun",
		"cn_name": "玩乐",
		"sign":    "fun",
		"children": map[int]map[string]string{
			3001: map[string]string{
				"en_name": "Casino",
				"cn_name": "赌场",
				"sort":    "1",
			},
			3002: map[string]string{
				"en_name": "Shoot",
				"cn_name": "射击场",
				"sort":    "2",
			},
			3003: map[string]string{
				"en_name": "Karting Car",
				"cn_name": "卡丁车",
				"sort":    "3",
			},
			3004: map[string]string{
				"en_name": "Ktv",
				"cn_name": "KTV",
				"sort":    "4",
			},
			3005: map[string]string{
				"en_name": "Red-light District",
				"cn_name": "红灯区",
				"sort":    "5",
			},
			3006: map[string]string{
				"en_name": "Road Trip",
				"cn_name": "自驾游",
				"sort":    "6",
			},
			3007: map[string]string{
				"en_name": "Cycling",
				"cn_name": "骑行",
				"sort":    "7",
			},
		},
	},
	4: map[string]interface{}{
		"en_name":  "Hotel",
		"cn_name":  "旅店",
		"sign":     "hotel",
		"children": map[int]map[string]string{},
	},
	5: map[string]interface{}{
		"en_name": "Facilitate",
		"cn_name": "便民",
		"sign":    "facilitate",
		"children": map[int]map[string]string{
			5001: map[string]string{
				"en_name": "Super Market",
				"cn_name": "超市",
				"sort":    "1",
			},
			5002: map[string]string{
				"en_name": "Milk Tea",
				"cn_name": "奶茶店",
				"sort":    "2",
			},
			5003: map[string]string{
				"en_name": "Rate",
				"cn_name": "换汇",
				"sort":    "3",
			},
			5004: map[string]string{
				"en_name": "Deliver",
				"cn_name": "外卖美食",
				"sort":    "4",
			},
			5005: map[string]string{
				"en_name": "Property",
				"cn_name": "房产",
				"sort":    "5",
			},
			5006: map[string]string{
				"en_name": "Service",
				"cn_name": "办证",
				"sort":    "6",
			},
			5007: map[string]string{
				"en_name": "Trip",
				"cn_name": "旅行社",
				"sort":    "7",
			},
			5008: map[string]string{
				"en_name": "Rent Car",
				"cn_name": "租车",
				"sort":    "8",
			},
			5009: map[string]string{
				"en_name": "Other",
				"cn_name": "其他",
				"sort":    "9",
			},
		},
	},
}

// 获取子类型的 按sort 排序
func GetElementTypeSortOptions(mainType int) ([]map[string]interface{}, error) {
	if _, ok := elementType[mainType]; !ok {
		return nil, fmt.Errorf("")
	}

	options := elementType[mainType]["children"]

	data := make([]map[string]interface{}, len(options.(map[int]map[string]string)))
	for i, v := range options.(map[int]map[string]string) {
		tmp := map[string]interface{}{
			"id":    i,
			"label": v["cn_name"],
		}
		index, _ := strconv.Atoi(v["sort"])
		data[index-1] = tmp
	}

	return data, nil
}

// 获取子类型的select option
func GetElementTypeSelectOptions(mainType int) ([]map[string]interface{}, error) {
	if _, ok := elementType[mainType]; !ok {
		return nil, fmt.Errorf("")
	}

	options := elementType[mainType]["children"]
	data := make([]map[string]interface{}, 0)
	for i, v := range options.(map[int]map[string]string) {
		tmp := map[string]interface{}{
			"id":    i,
			"label": v["cn_name"],
		}

		data = append(data, tmp)
	}
	return data, nil
}

// 获取类型名称
func GetTypeName(mainType int, subType int) (string, error) {
	if _, ok := elementType[mainType]; !ok {
		return "", fmt.Errorf("")
	}

	subOptions := elementType[mainType]["children"].(map[int]map[string]string)

	if _, ok := subOptions[subType]; !ok {
		return "", fmt.Errorf("")
	}

	return subOptions[subType]["cn_name"], nil
}

// 是否存在主类型
func IsHasMainType(mainType int) bool {
	if _, ok := elementType[mainType]; !ok {
		return false
	}
	return true
}

// 是否存在子类型
func IsHasSubType(mainType int, subType int) bool {
	if _, ok := elementType[mainType]; !ok {
		return false
	}

	subOptions := elementType[mainType]["children"].(map[int]map[string]string)
	if _, ok := subOptions[subType]; !ok {
		return false
	}
	return true
}
